`timescale 1ns/1ns

`include "uvm_macros.svh"
import uvm_pkg::*;

`include "mii_if.sv"
`include "testcases/test_base.sv"
`include "testcases/mac_multi_port_transfer_smoke.sv"
`include "testcases/mac_single_port_polling_smoke.sv"
`include "testcases/mac_crc_error_smoke.sv"
`include "testcases/mac_lut_study_smoke.sv"
`include "testcases/switch_random_test.sv"
`include "testcases/cover_case.sv"
`include "testcases/perf_test.sv"

parameter PORT_NUM = 4;

module switch_tb;

	logic clk;
	logic rst_n;

	mii_if in_mii_if(clk, rst_n);
	mii_if out_mii_if(clk, rst_n);
	test_if m_test_if(clk, rst_n);

	initial begin
		clk = 0;
		forever begin
			#5 clk = ~clk;
		end
	end

	initial begin
		in_mii_if.mii_rx_clk = 0;
		forever begin
			#20 in_mii_if.mii_rx_clk[PORT_NUM - 1 : 0] = ~in_mii_if.mii_rx_clk[PORT_NUM - 1 : 0];
		end
	end

	initial begin
		out_mii_if.mii_rx_clk[PORT_NUM - 1 : 0] = 0;
		forever begin
			#20 out_mii_if.mii_rx_clk[PORT_NUM - 1 : 0] = ~out_mii_if.mii_rx_clk[PORT_NUM - 1 : 0];
		end
	end

	initial begin
		in_mii_if.mii_tx_clk = 0;
		forever begin
			#20 in_mii_if.mii_tx_clk[PORT_NUM - 1 : 0] = ~in_mii_if.mii_tx_clk[PORT_NUM - 1 : 0];
		end
	end

	initial begin
		out_mii_if.mii_tx_clk = 0;
		forever begin
			#20 out_mii_if.mii_tx_clk[PORT_NUM - 1 : 0] = ~out_mii_if.mii_tx_clk[PORT_NUM - 1 : 0];
		end
	end

	initial begin
		rst_n = 0;
		#100;
		rst_n = 1;
	end

	switch_top_v1 #(
		.PORT_NUM(PORT_NUM)
	)
	test_switch_top(
		.clk			(clk),
		.rst_n			(rst_n),
		.mii_rx_clk		(in_mii_if.mii_tx_clk),
		.mii_rx_dv		(in_mii_if.mii_tx_en),
		.mii_rxd		(in_mii_if.mii_tx_data),
		.drop_num		(m_test_if.drop_num),
		.mii_tx_clk		(out_mii_if.mii_rx_clk),
		.mii_tx_en		(out_mii_if.mii_rx_dv),
		.mii_txd		(out_mii_if.mii_rx_data)
	);

	initial begin
		for (int i = 0; i < PORT_NUM; i++) begin
 			uvm_config_db #(virtual mii_if #(PORT_NUM))::set(null, $sformatf("uvm_test_top.env.i_agent_%0d.*", i), "vif", in_mii_if);
			uvm_config_db #(virtual mii_if #(PORT_NUM))::set(null, $sformatf("uvm_test_top.env.o_agent_%0d.*", i), "vif", out_mii_if);
		end
		uvm_config_db #(virtual mii_if #(PORT_NUM))::set(null, "uvm_test_top.env.virt_sqr", "vif", in_mii_if);

		uvm_config_db #(virtual mii_if #(PORT_NUM))::set(null, "uvm_test_top.env.cov", "in_vif", in_mii_if);
		uvm_config_db #(virtual mii_if #(PORT_NUM))::set(null, "uvm_test_top.env.cov", "out_vif", out_mii_if);
		uvm_config_db #(virtual test_if #(PORT_NUM))::set(null, "uvm_test_top.env.m_scb", "t_if", m_test_if);
 		run_test();

	end

	initial begin
`ifdef FSDB_FLAG
		string testname;
		if($value$plusargs("TESTNAME=%s", testname)) begin
			$fsdbDumpfile({testname, ".fsdb"});
		end else begin
			$fsdbDumpfile("tb.fsdb");
		end
		$fsdbDumpvars(0, switch_tb);
		$fsdbDumpMDA();
`endif
	end



endmodule

